package com.example.webwork.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.webwork.dto.AuthorArticleCount;
import com.example.webwork.entity.Article;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ArticleMapper extends BaseMapper<Article> {

    @Select("SELECT u.username, COUNT(a.username) AS count " +
            "FROM user u " +
            "LEFT JOIN article a ON u.username = a.username " +
            "GROUP BY u.username")
    List<AuthorArticleCount> getAuthorArticleCount();
}
